package com.tedu.spring.boot.demo1.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Author：毕龙
 * Date: 2024/8/27 14:54
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class JSONResult {
    private Integer code;//响应状态码
    private Object data;//响应的数据
    private String msg;//响应信息

    public JSONResult(Object data,ResponseStatus responseStatus){
        this.code = responseStatus.getCode();
        this.data = data;
        this.msg = responseStatus.getMsg();
    }

    public JSONResult(ResponseStatus responseStatus){
        this.code = responseStatus.getCode();
        this.msg = responseStatus.getMsg();
    }

    public JSONResult(ResponseStatus responseStatus,String msg){
        this.code = responseStatus.getCode();
        this.msg = msg;
    }

    public static JSONResult ok(Object data){
        return new JSONResult(data,ResponseStatus.SUCCESS_OK);
    }
    public static JSONResult ok(){
        return new JSONResult(ResponseStatus.SUCCESS_OK);
    }

    public static JSONResult fail(){
        return new JSONResult(ResponseStatus.ERROR_FAIL);
    }
    public static JSONResult fail(ResponseStatus status,String msg){
        return new JSONResult(status,msg);
    }

}
